<?php
namespace Home\Model;

use Think\Model;

class ExpenseScheduleModel extends Model{
	
	const DELETE_STATUS = -1;
	
	protected $tableName = 'expense_schedule';
   
    //费用类型
    protected $expenseType = array(
     '1'=>'采购费用',
     '2'=>'活动费用',
     '3'=>'出差费用',
     '4'=>'报修费用',
     '5'=>'其它费用',
    );
	
	
	
	//部门列表
	protected $department = array(
     '1'=>'人事部',
     '2'=>'销售部',
     '3'=>'客服部',
     '4'=>'风控部',
    );
	
	//月份列表
	protected $month = array(
     '1'=>'一月',
     '2'=>'二月',
     '3'=>'三月',
     '4'=>'四月',
     '5'=>'五月',
     '6'=>'六月',
     '7'=>'七月',
     '8'=>'八月',
     '9'=>'九月',
     '10'=>'十月',
     '11'=>'十一月',
     '12'=>'十二月',
    );
	
	
	

    protected $_auto = array(
        array('start', 'transfer', 1, 'callback'),
        array('end', 'transfer', 1, 'callback'),
        array('user_id', 'getUserId', 1, 'callback'),
    );
    //UTC时间转换
    public function transfer($v){
      if (empty($v)) {
        return null;
      } else {
        return UTC_to_locale_time($v);
      }
    }

    //获取user_id
    public function getUserId(){
    	if(session('uid')){
    		$user_id=session('uid');
    		return $user_id;
    	}
    }

    /**
    * 返回类型 或 所有的类型
    * 
    * @return string|array
    */
    public function getExpenseType($index){
    	if (!empty($index)) {
    		return $this->expenseType[$index];
    	} else {
    		return $this->expenseType;
    	}
    }
	
	
	
	public function getDepartmentType($index){
    	if (!empty($index)) {
    		return $this->department[$index];
    	} else {
    		return $this->department;
    	}
    }
	
	public function getMonthType($index){
    	if (!empty($index)) {
    		return $this->month[$index];
    	} else {
    		return $this->month;
    	}
    }

    public function delete($ids=array()){
        // return $this->where(array('id'=>array('in', $ids )))->save(array('status'=>-1));
        $id_arr = explode(",", $ids);
        return $this->data(array('info_status'=>self::DELETE_STATUS))->where(array('id'=> array('in', $id_arr)))->save();
    }


    

}